<template>
    <div>
        <h2>我是登陆组件</h2>
        用户名<input v-model="user" type="text">
        密码<input v-model="pwd" type="text">
        <button @click="login">登录</button><br><br>
        <button @click='getData'>获取数据</button>
    </div>
</template>
<script>
import { mapActions } from 'vuex'
import * as url from '../api/api.js'
// import axios from 'axios'

export default {
    name: 'Login',
    data() {
        return {
            user: '',
            pwd: ''
        }
    },
    methods: {
        ...mapActions(['userLogin']),
        login() {
            // 这里要调用登录的方法
            // 获取用户名和密码
            let obj = {
                user: this.user,
                pwd: this.pwd
            }
            this.userLogin(obj)
                .then(res => {
                    
                    if (res.code === 200) {
                        console.log(res)
                        this.$router.push('/')
                    }
                }).catch(err => {
                    console.log(err)
                })
        },
        getData() {
            this.$axios.post(url.getData, {})
                .then(res => {
                    console.log(res)
                })
                .catch(error => {
                    console.log(error)
                })
        }
    }
}
</script>